class code2 {
    //k个元素的小根堆

    PriorityQueue<Integer> heap = new PriorityQueue<>();
    int _k;

    public KthLargest(int k, int[] nums) {
        _k = k;
        for(int x:nums) {
            heap.offer(x);
            if(heap.size()>k) {
                heap.poll();
            }
        }
    }

    public int add(int val) {
        heap.offer(val);
        if(heap.size()>_k) {
            heap.poll();
        }
        return heap.peek();
    }
}